var treeview = function(data,pid){
    var r = data[pid||0] || [],res = [];
    if (r.length) {
        for(var i=0,j=r.length;i<j;i++){
            if (r[i]['level'] > 0) {
                var pad = new Array(r[i]['level']*1);
                //r[i]['prefix'] = pad.join("|\u00A0\u00A0") + "|\u00A0\u00A0-"
                r[i]['prefix'] = pad.join("\u00A0\u00A0\u00A0\u00A0") + ""
                //r[i]['prefix'] = pad.join("/@@") + "|-"
            }
            res.push(r[i]);
            if(data.hasOwnProperty(r[i]['id'])){
                res = res.concat(treeview(data,r[i]['id']));
            }
        }
    }
    return res;
}
var treedata = function(data,pid,pidvalue){
    var tree = {},res = [],pidvalue = pidvalue || 0;
    for(var i=0,j=data.length;i<j;i++){
        tree[data[i][pid]] = tree[data[i][pid]] || []
        tree[data[i][pid]].push(data[i]);
    }
    return tree
}
var treeReverseChain = function(data,pid,pidvalue){
    var tree = treedata(data,pid,pidvalue)

}
var treestruct = function(data,pid,pidvalue){
    return treeview(treedata(data,pid,pidvalue),pidvalue);
}

export default {
    make : treestruct,
    raw : treedata
}
